home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 5 / 005.d81 / dos part 11 < prev    next >
Text File  |  2022-08-26  |  3KB  |  151 lines

  1.  
  2.      Dos 'n' Don'ts --- Part 11
  3.  
  4.          by Joel Ellis Rea
  5.  
  6. --------------------------------------
  7.  
  8.   Now you know how the Command/Error
  9.  
  10. channel got its name.  When
  11.  
  12. information is sent to the drive
  13.  
  14. through the Command/Error channel, it
  15.  
  16. is considered to be a disk command.
  17.  
  18. When information is requested from the
  19.  
  20. drive through the Command/Error
  21.  
  22. channel, it is the Disk Drive Error
  23.  
  24. Status.  Thus, a PRINT# 15, where
  25.  
  26. Logical File Number 15 was OPENed as
  27.  
  28. the Command/Error channel of a disk
  29.  
  30. drive, sends a command to the drive,
  31.  
  32. while INPUT# 15 asks for drive status.
  33.  
  34.  
  35.   As an example, let's write a short
  36.  
  37. program that asks the user for the
  38.  
  39. name of a file, then tells the user if
  40.  
  41. that file exists on the disk or not.
  42.  
  43. The way we will tell is by asking the
  44.  
  45. drive to Rename the file to its own
  46.  
  47. name.  If the Rename succeeds, no harm
  48.  
  49. is done, since the new name equals the
  50.  
  51. old name!  If it does not succeed, we
  52.  
  53. can find out why not.  One possible
  54.  
  55. error message we might get back is
  56.  
  57. Error #63, 'FILE NOT FOUND'.  Q.E.D.
  58.  
  59.  
  60.   10 PRINT "[clr]"
  61.   20 OPEN 15,8,15,"I0":GOSUB 200
  62.   30 IF ER% > 19 THEN END
  63.   40 INPUT "FILE NAME"; F$
  64.   50 PRINT#15, "R0:"; F$; "="; F$
  65.   60 GOSUB 200
  66.   70 IF ER% > 29 AND ER% < 40 THEN
  67.      PRINT "BAD FILENAME": GOTO 40
  68.   80 IF ER% = 62 THEN PRINT F$;
  69.      "IS NOT ON THE DISKETTE!": END
  70.   90 IF ER% = 63 THEN PRINT F$;
  71.      "IS ON THE DISKETTE!": END
  72.  100 PRINT "ERROR #";ER%: PRINT ER$:
  73.      END
  74.  200 INPUT#15, ER%, ER$, ET%, EB%
  75.  210 IF ER% = 74 THEN PRINT
  76.      "DOOR OPEN OR NO DISKETTE"
  77.  220 IF ER% > 19 AND ER% < 30 THEN
  78.      PRINT "BAD DISKETTE"
  79.  230 RETURN
  80.  
  81.  
  82.   This program begins by clearing the
  83.  
  84. screen, then OPENing the Command/Error
  85.  
  86. channel and sending an Initialize
  87.  
  88. command in one step.  A subroutine at
  89.  
  90. line 200 obtains the disk status and
  91.  
  92. puts the status code in ER%.  Then it
  93.  
  94. checks it against some common errors.
  95.  
  96. Any error code less than 20 is
  97.  
  98. considered OK.
  99.  
  100.  
  101.   We then ask the user for a filename
  102.  
  103. (line 40) then Rename it to itself
  104.  
  105. (line 50).  Again we call the
  106.  
  107. subroutine (line 60) to determine the
  108.  
  109. Drive Status.  We first check for a
  110.  
  111. 'SYNTAX ERROR', which could be caused
  112.  
  113. by a bad file name.  Then we check for
  114.  
  115. a 'FILE NOT FOUND', which would tell
  116.  
  117. us that the file does not exist on the
  118.  
  119. diskette.  If the command succeeds,
  120.  
  121. ('FILE EXISTS'), the file is on the
  122.  
  123. diskette.  We notify the user in any
  124.  
  125. case.
  126.  
  127.  
  128.   For all you one-finger typists (we
  129.  
  130. all started that way) we have entered
  131.  
  132. the program above to save you the
  133.  
  134. trouble.  You'll find it on this side
  135.  
  136. of LOADSTAR named 'DOS EXAMPLE 1'.
  137.  
  138. Take a good look at it.  LIST it.  RUN
  139.  
  140. it.  Modify it to do other things.  Be
  141.  
  142. SURE you understand the Command/Error
  143.  
  144. channel.  It is a powerful tool which
  145.  
  146. you will need to understand when you
  147.  
  148. start using data files.
  149.  
  150. ---------- End of Article ------------
  151.